/*
 * Copyright 2006-2022 ahtelit.com, All Rights Reserved.
 */

package com.telit.firecommand.feign.factory;

import com.telit.android.dto.CommMsgCenterLogDTO;
import com.telit.android.dto.IssueFireVerificationTask;
import com.telit.android.dto.PushFireMsg;
import com.telit.common.entity.DataReturn;
import com.telit.common.entity.PageData;
import com.telit.common.enums.ResultCode;
import com.telit.common.util.LanguageUtils;
import com.telit.firecommand.dto.FireQueryListDTO;
import com.telit.firecommand.entity.CommFireAlarm;
import com.telit.firecommand.feign.RemoteFirecommandService;
import com.telit.firecommand.model.sysUser.UpdateUserRequest;
import com.telit.firecommand.vo.ForesterVO;
import com.telit.firecommand.vo.MicroSysUserVO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * RemoteFirecommandServiceFallbackFactory
 *
 * @author yuezhuang
 * @since 2022-12-14
 */
@Slf4j
@Component
public class RemoteFirecommandServiceFallbackFactory implements FallbackFactory<RemoteFirecommandService> {

    @Override
    public RemoteFirecommandService create(Throwable cause) {
        return new RemoteFirecommandService() {
            /**
             * 标准化输出微服务内部调用错误信息
             *
             * @return DataReturn
             */
            private DataReturn defaultFallback() {
                String msg = LanguageUtils.codeMessage(ResultCode.SERVER_FEIGN_ERROR.getCode(), cause.getMessage());
                log.error(msg, cause);
                return DataReturn.failure(ResultCode.SERVER_FEIGN_ERROR.getCode(), msg);
            }

            @Override
            public DataReturn uavInfoByFireId(Long fireId, Long userId) {
                return defaultFallback();
            }

            @Override
            public DataReturn getNameFromCode(String code) {
                return defaultFallback();
            }

            @Override
            public DataReturn addBatch(CommMsgCenterLogDTO dto) {
                return defaultFallback();
            }

            @Override
            public DataReturn queryAddressById(String fireId) {
                return defaultFallback();
            }

            @Override
            public DataReturn detail(String id) {
                return defaultFallback();
            }

            @Override
            public DataReturn queryLongitudeAndLatitude(String fireId) {
                return defaultFallback();
            }

            @Override
            public DataReturn addFireDispose(PushFireMsg pushFireMsg) {
                return defaultFallback();
            }

            @Override
            public DataReturn addTaskDispose(IssueFireVerificationTask issueFireVerificationTask) {
                return defaultFallback();
            }

            @Override
            public DataReturn getDistrictNameAndCodeByPoint(String longitude, String latitude) {
                return defaultFallback();
            }

            @Override
            public DataReturn<MicroSysUserVO> updateUser(UpdateUserRequest updateUserRequest) {
                return defaultFallback();
            }

            @Override
            public DataReturn<PageData<List<CommFireAlarm>>> queryFireByPage(FireQueryListDTO fireQueryListDTO) {
                return defaultFallback();
            }

            @Override
            public DataReturn countForesterByCondition(String name, String districtCode) {
                return defaultFallback();
            }

            @Override
            public DataReturn<PageData<List<CommFireAlarm>>> queryAllHistoryFire(String startTime, String endTime,
                                                                                 String districtCode, String fireLevel,
                                                                                 String resource, Integer page,
                                                                                 Integer rows) {
                return defaultFallback();
            }

            @Override
            public DataReturn<PageData<List<CommFireAlarm>>> queryAllFireByCondition(String status, String startTime,
                                                                                     String endTime,
                                                                                     String districtCode,
                                                                                     String resource, String action,
                                                                                     String finalLevel, Integer pageNum,
                                                                                     Integer pageSize) {
                return defaultFallback();
            }

            @Override
            public DataReturn<PageData<List<ForesterVO>>> qryUserList(String name, Integer onlineStatus,
                                                                      String regionCode, boolean areaRecursion,
                                                                      String roleCodes, String ids, Integer current,
                                                                      Integer size) {
                return defaultFallback();
            }

            @Override
            public DataReturn<ForesterVO> qryUserDetail(Long id) {
                return defaultFallback();
            }

            @Override
            public DataReturn<List<Long>> qryUserIdList(String name, Integer onlineStatus,
                                                        String regionCode, boolean areaRecursion,
                                                        String roleCodes) {
                return defaultFallback();
            }
        };
    }

}
